ddns-scripts: stash the next check time
authorPaul Donald <[email protected]>
Thu, 18 Sep 2025 23:21:05 +0000 (01:21 +0200)
committerFlorian Eckert <[email protected]>
Tue, 23 Sep 2025 07:12:10 +0000 (09:12 +0200)
Calculating the next check time based on the last update time is not
very accurate if the next check is a large multiple forwards from the
last update time because the cumulative sleeps and wake times are not
exact but best effort of the OS. Other factors including clock-drift
give rise to a larger time discrepancy the further the next update is in
the future.

Stash the next check time which should be quite accurate since it's
only one sleep instance away. This is also for use in the GUI.

Tested on 24.10.2

Signed-off-by: Paul Donald <[email protected]>
net/ddns-scripts/Makefile
net/ddns-scripts/files/usr/lib/ddns/dynamic_dns_updater.sh

index 4e306b28bb60af5ea8c494afe1105f8f2257358a..00f4b971aa4599f2a5604d23406952001589f19b 100644 (file)
@@ -8,7 +8,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=ddns-scripts
 PKG_VERSION:=2.8.2
-PKG_RELEASE:=77
+PKG_RELEASE:=78
 
 PKG_LICENSE:=GPL-2.0
 
index ffd7f2710cd1a8f08450de84073593a9251c5365..f14941f309e723e38e17b06d57babd0cee617c0e 100644 (file)
@@ -102,6 +102,7 @@ esac
 # set file names
 PIDFILE="$ddns_rundir/$SECTION_ID.pid" # Process ID file
 UPDFILE="$ddns_rundir/$SECTION_ID.update"      # last update successful send (system uptime)
+CHKFILE="$ddns_rundir/$SECTION_ID.nextcheck" # next check (system uptime + check interval)
 DATFILE="$ddns_rundir/$SECTION_ID.dat" # save stdout data of WGet and other extern programs called
 ERRFILE="$ddns_rundir/$SECTION_ID.err" # save stderr output of WGet and other extern programs called
 IPFILE="$ddns_rundir/$SECTION_ID.ip"   #
@@ -397,7 +398,10 @@ while : ; do
 
        # now we wait for check interval before testing if update was recognized
        [ $DRY_RUN -eq 0 ] && {
-               write_log 7 "Waiting $CHECK_SECONDS seconds (Check Interval)"
+               get_uptime NOW_TIME
+               echo $(($NOW_TIME + $CHECK_SECONDS)) > $CHKFILE   # save the next scheduled check time
+               NEXT_CHECK_TIME=$( date -d @$(( $(date +%s) + $CHECK_SECONDS )) +"$ddns_dateformat" )
+               write_log 7 "Waiting $CHECK_SECONDS seconds (Check Interval); Next check at $NEXT_CHECK_TIME"
                sleep $CHECK_SECONDS &
                PID_SLEEP=$!
                wait $PID_SLEEP # enable trap-handler